package com.xb.service;

import com.xb.dao.MeetingDao;
import com.xb.entity.Meeting;
import com.xb.utils.PageEntity;

import java.util.List;

public class MeetingService {
    private MeetingDao meetingDao=new MeetingDao();


    /**
     * 会议搜索+分页
     * @param title
     * @param status
     * @param currPage
     * @return
     */
    public PageEntity<Meeting> findPage(String title, String status, Integer currPage) {
        PageEntity<Meeting> pageData=new PageEntity<>();

        // 页大小
        Integer pageSize = pageData.getPageSize();


        // 当前页的数据
        Integer startIndex = (currPage - 1) * pageSize;
        List<Meeting> meetingList = meetingDao.findPage(title, status, startIndex, pageSize);


        // 总记录数
        Integer totalCount = meetingDao.findPageCount(title, status);


        // 总页数
        Integer totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;

        pageData.setCurrPage(currPage);
        pageData.setData(meetingList);
        pageData.setTotalPage(totalPage);
        pageData.setTotalPage(totalPage);

        return pageData;

    }


    /**
     * 发布会议
     * @param meeting
     */
    public void save(Meeting meeting) {
        meetingDao.save(meeting);

    }


    /**
     * 会议详情
     * @param meetingId
     * @return
     */
    public Meeting findById(Long meetingId) {
        return meetingDao.findById(meetingId);
    }


    /**
     * 会议实到人数
     * @param meetingId
     * @return
     */
    public Integer findRealCount(Long meetingId) {
        return meetingDao.findRealCount(meetingId);
    }


    /**
     * 我是否已经参加了本次会议
     * @param id
     * @param meetingId
     * @return
     */
    public Boolean isJoinMeeting(Long id, Long meetingId) {
        return meetingDao.isJoinMeeting(id,meetingId)>0;
    }


    /**
     * 取消会议
     * @param id
     * @param meetingId
     */
    public void delJoinMeeting(Long id, Long meetingId) {
        meetingDao.delJoinMeeting(id,meetingId);
    }


    /**
     * 参加会议
     * @param id
     * @param meetingId
     */
    public void joinMeeting(Long id, Long meetingId) {
        meetingDao.joinMeeting(id,meetingId);
    }
}
